package com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog;

import com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog.vo.RollCheckLogCreateReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog.vo.RollCheckLogExcelVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog.vo.RollCheckLogExportReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog.vo.RollCheckLogPageReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog.vo.RollCheckLogRespVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog.vo.RollCheckLogUpdateReqVO;
import com.nanhai.buddhist.college.module.collegebase.convert.rollchecklog.RollCheckLogConvert;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.rollchecklog.RollCheckLogDO;
import com.nanhai.buddhist.college.module.collegebase.service.rollchecklog.RollCheckLogService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import static com.nanhai.buddhist.college.framework.common.pojo.CommonResult.success;

import com.nanhai.buddhist.college.framework.excel.core.util.ExcelUtils;

import com.nanhai.buddhist.college.framework.operatelog.core.annotations.OperateLog;
import static com.nanhai.buddhist.college.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog.vo.*;

@Api(tags = "管理后台 - 学籍信息审核记录")
@RestController
@RequestMapping("/collegebase/roll-check-log")
@Validated
public class RollCheckLogController {

    @Resource
    private RollCheckLogService rollCheckLogService;

    @PostMapping("/create")
    @ApiOperation("创建学籍信息审核记录")
    @PreAuthorize("@ss.hasPermission('collegebase:roll-check-log:create')")
    public CommonResult<String> createRollCheckLog(@Valid @RequestBody RollCheckLogCreateReqVO createReqVO) {
        return success(rollCheckLogService.createRollCheckLog(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新学籍信息审核记录")
    @PreAuthorize("@ss.hasPermission('collegebase:roll-check-log:update')")
    public CommonResult<Boolean> updateRollCheckLog(@Valid @RequestBody RollCheckLogUpdateReqVO updateReqVO) {
        rollCheckLogService.updateRollCheckLog(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除学籍信息审核记录")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('collegebase:roll-check-log:delete')")
    public CommonResult<Boolean> deleteRollCheckLog(@RequestParam("id") String id) {
        rollCheckLogService.deleteRollCheckLog(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得学籍信息审核记录")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('collegebase:roll-check-log:query')")
    public CommonResult<RollCheckLogRespVO> getRollCheckLog(@RequestParam("id") String id) {
        RollCheckLogDO rollCheckLog = rollCheckLogService.getRollCheckLog(id);
        return success(RollCheckLogConvert.INSTANCE.convert(rollCheckLog));
    }

    @GetMapping("/list")
    @ApiOperation("获得学籍信息审核记录列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('collegebase:roll-check-log:query')")
    public CommonResult<List<RollCheckLogRespVO>> getRollCheckLogList(@RequestParam("ids") Collection<String> ids) {
        List<RollCheckLogDO> list = rollCheckLogService.getRollCheckLogList(ids);
        return success(RollCheckLogConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得学籍信息审核记录分页")
    @PreAuthorize("@ss.hasPermission('collegebase:roll-check-log:query')")
    public CommonResult<PageResult<RollCheckLogRespVO>> getRollCheckLogPage(@Valid RollCheckLogPageReqVO pageVO) {
        PageResult<RollCheckLogDO> pageResult = rollCheckLogService.getRollCheckLogPage(pageVO);
        return success(RollCheckLogConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出学籍信息审核记录 Excel")
    @PreAuthorize("@ss.hasPermission('collegebase:roll-check-log:export')")
    @OperateLog(type = EXPORT)
    public void exportRollCheckLogExcel(@Valid RollCheckLogExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<RollCheckLogDO> list = rollCheckLogService.getRollCheckLogList(exportReqVO);
        // 导出 Excel
        List<RollCheckLogExcelVO> datas = RollCheckLogConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "学籍信息审核记录.xls", "数据", RollCheckLogExcelVO.class, datas);
    }

}
